package com.tancire.web.controller.works;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tancire.common.annotation.Log;
import com.tancire.common.core.controller.BaseController;
import com.tancire.common.core.domain.AjaxResult;
import com.tancire.common.enums.BusinessType;
import com.tancire.works.domain.SideWorkType;
import com.tancire.works.service.ISideWorkTypeService;
import com.tancire.common.utils.poi.ExcelUtil;
import com.tancire.common.core.page.TableDataInfo;

/**
 * 兼职类型Controller
 *
 * @author tancire
 * @date 2024-03-02
 */
@RestController
@RequestMapping("/works/sideWorkType")
public class SideWorkTypeController extends BaseController {
    @Resource
    private ISideWorkTypeService sideWorkTypeService;

    /**
     * 查询兼职类型列表
     */
    @PreAuthorize("@ss.hasPermi('works:sideWorkType:list')")
    @GetMapping("/list")
    public TableDataInfo list(SideWorkType sideWorkType) {
        startPage();
        List<SideWorkType> list = sideWorkTypeService.selectSideWorkTypeList(sideWorkType);
        return getDataTable(list);
    }

    /**
     * 查询兼职类型列表
     */
    @GetMapping("/listAll")
    public AjaxResult listAll(SideWorkType sideWorkType) {
        List<SideWorkType> list = sideWorkTypeService.selectSideWorkTypeList(sideWorkType);
        return AjaxResult.success("查询成功", list);
    }

    /**
     * 导出兼职类型列表
     */
    @PreAuthorize("@ss.hasPermi('works:sideWorkType:export')")
    @Log(title = "兼职类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SideWorkType sideWorkType) {
        List<SideWorkType> list = sideWorkTypeService.selectSideWorkTypeList(sideWorkType);
        ExcelUtil<SideWorkType> util = new ExcelUtil<SideWorkType>(SideWorkType.class);
        util.exportExcel(response, list, "兼职类型数据");
    }

    /**
     * 获取兼职类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('works:sideWorkType:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(sideWorkTypeService.selectSideWorkTypeById(id));
    }

    /**
     * 新增兼职类型
     */
    @PreAuthorize("@ss.hasPermi('works:sideWorkType:add')")
    @Log(title = "兼职类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SideWorkType sideWorkType) {
        return toAjax(sideWorkTypeService.insertSideWorkType(sideWorkType));
    }

    /**
     * 修改兼职类型
     */
    @PreAuthorize("@ss.hasPermi('works:sideWorkType:edit')")
    @Log(title = "兼职类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SideWorkType sideWorkType) {
        return toAjax(sideWorkTypeService.updateSideWorkType(sideWorkType));
    }

    /**
     * 删除兼职类型
     */
    @PreAuthorize("@ss.hasPermi('works:sideWorkType:remove')")
    @Log(title = "兼职类型", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sideWorkTypeService.deleteSideWorkTypeByIds(ids));
    }
}
